// pages/follow/follow.js
//获取应用实例
const app = getApp()
const util = require('../../utils/util.js')
Page({

  data: {
    host:app.globalData.host,
    TabCur: 0,
    type:1,
    modalName:'',
    scrollLeft:0,
    tabList:[
      {
        name:'用户', 
        type:1,
      },
      {
        name:'话题', 
        type:2,
      },
      {
        name:'医生', 
        type:3,
      },
    ]
  },

  /**
   * 取消关注
   * @param {*} e 
   */
  nofollow:function(e){
    var nofollow_id = this.data.nofollow_id;
    var that = this;
    util.request('follow/deleteById', {id:nofollow_id}, function (data) {
      console.log(data);
      if(data.code == 1){
        that.setData({
          nofollow_id:''
        })
        that.hideModal();
        wx.showToast({
          title: '操作成功',
          icon: 'success',
          duration: 1500
        })
        setTimeout(function(){
          that.getMsgList(1,'');
        },1500)
      }else{
        that.setData({
          nofollow_id:''
        })
        util.fail(data.msg,that);
      }
    });
  },

  showModal:function(e){
    this.setData({
      modalName: 'modal1',
      nofollow_id:e.target.dataset.id
    })
  },
  hideModal:function(){
    this.setData({
      modalName: '',
    })
  },
  
  tabSelect(e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id-1)*60
    })
    this.setData({
      type:this.data.tabList[this.data.TabCur].type
    })
    this.getMsgList(1,'');
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //内容列表
    this.getMsgList(1,'');
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  onPullDownRefresh: function () {
    if (!this.loading) {
      wx.showNavigationBarLoading();
      this.getMsgList(1,'top');
    }
  },

  onReachBottom: function () {
    var that = this;
    if (!this.data.loading && this.data.page < this.data.pages) {
      that.setData({
        isHideLoadMore: false,
        page: this.data.page+1
      });
      console.log(that.data.page);
      this.getMsgList(that.data.page, 'bottom');
    }
  },

  getMsgList: function(pageNo,pos) {
    var url = 'follow/index',param = {type:this.data.type};
    param.pageNo = pageNo;
    util.pageList(this,url,param, pos);
  },
})